package admin_server

import (
	"github.com/prometheus/client_golang/prometheus"
	"lark/server_agent"
)

type StatCollector struct {
	blockingTaskNum *prometheus.Desc
}

func NewStatCollector() prometheus.Collector {
	return &StatCollector{
		blockingTaskNum: prometheus.NewDesc(
			"blocking_task_num",
			"number of blocking task in queue",
			[]string{"service_name"},
			nil,
		),
	}
}

func (c *StatCollector) Describe(ch chan<- *prometheus.Desc) {
	ch <- c.blockingTaskNum
}

func (c *StatCollector) Collect(ch chan<- prometheus.Metric) {
	names, nums := server_agent.DefaultProxyManager.BlockingTask()
	for i := 0; i < len(names); i++ {
		ch <- prometheus.MustNewConstMetric(c.blockingTaskNum, prometheus.GaugeValue, float64(nums[i]), names[i])
	}
}
